package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import cn.jhc.bean.User;
import cn.jhc.db.UserDao;
import uuntil.*;
/**
 * Servlet implementation class RegisterServlet
 */
@WebServlet("/register.do")
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
    

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);
		request. setCharacterEncoding("UTF-8");
		String username =request.getParameter("username");
		String password =request.getParameter("password");
		String email =request.getParameter("email");
		User u=new User(username,email,password);
		UserDao.addUser(dataSource,u);
		response.sendRedirect("./succeed.do");
	}

}
